home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_061 / microemacs / st520.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  10KB  |  538 lines

  1. /*
  2.  
  3. The routines in this file provide support for the Atari ST520 or 1040
  4. using VT52 emulation.  The I/O services are provided by routines in
  5. "termio.c".  It compiles into nothing if not a ST520 style device.  The
  6. bell on the ST520 is terrible, so the "beep" routine is conditionalized
  7. on defining BEL. 
  8.  
  9. */
  10.  
  11. #define    termdef    1            /* don't define "term" external */
  12.  
  13. #include        <stdio.h>
  14. #include        "estruct.h"
  15. #include    "edef.h"
  16.  
  17. #if MEGAMAX
  18. overlay "st520"
  19. #endif
  20.  
  21. #if     ATARI & ST520 & MEGAMAX
  22. #include    <osbind.h>
  23. #include    <ctype.h>
  24.  
  25. #define LINEA_INIT 0xA000
  26. #define V_CEL_WR   -0x28
  27. #define V_CEL_MY   -0x2a
  28. #define V_CEL_HT   -0x2e
  29. #define V_FNT_AD   -0x16
  30. #define V_OFF_AD   -0x0a
  31. #define V_DISAB    -346
  32.  
  33. #define NROW    24                      /* Screen size.                 */
  34. #define NCOL    80                      /* Edit if you want to.         */
  35. #define    MARGIN    8            /* size of minimim margin and    */
  36. #define    SCRSIZ    64            /* scroll size for extended lines */
  37. #define    NPAUSE    25            /* # times thru update to pause */
  38. #define BIAS    0x20                    /* Origin 0 coordinate bias.    */
  39. #define ESC     0x1B                    /* ESC character.               */
  40. #define BEL     0x07                    /* ascii bell character         */
  41.  
  42. extern  int     ttopen();               /* Forward references.          */
  43. extern  int     ttgetc();
  44. extern  int     ttputc();
  45. extern  int     ttflush();
  46. extern  int     ttclose();
  47. extern  int     st520move();
  48. extern  int     st520eeol();
  49. extern  int     st520eeop();
  50. extern  int     st520beep();
  51. extern  int     st520open();
  52. extern    int    st520close();
  53. extern    int    st520rev();
  54. extern    int    st520cres();
  55. extern  int st520kopen();
  56. extern  int st520kclose();
  57.  
  58. #if    COLOR
  59. extern    int    st520fcol();
  60. extern    int    st520bcol();
  61.  
  62. int        cfcolor = -1;        /* current fg (character) color */
  63. int        cbcolor = -1;        /* current bg color */
  64. int        oldpal[8];        /* pallette when emacs was invoked */
  65. int        newpal[8] = {        /* default emacs pallette */
  66.     0x000, 0x700, 0x070, 0x770, 0x007, 0x707, 0x077, 0x777};
  67. #endif
  68.  
  69. int STncolors = 0;        /* number of colors  */
  70. int STrez;            /* physical screen resolution */    
  71.  
  72. /*
  73.  * Dispatch table. All the
  74.  * hard fields just point into the
  75.  * terminal I/O code.
  76.  */
  77. TERM    term    = {
  78.         NROW-1,
  79.         NCOL,
  80.     MARGIN,
  81.     MARGIN,
  82.     SCRSIZ,
  83.     NPAUSE,
  84.         &st520open,
  85.         &st520close,
  86.     &st520kopen,
  87.     &st520kclose,
  88.         &ttgetc,
  89.         &ttputc,
  90.         &ttflush,
  91.         &st520move,
  92.         &st520eeol,
  93.         &st520eeop,
  94.         &st520beep,
  95.         &st520rev,
  96.         &st520cres
  97. #if    COLOR
  98.     , &st520fcol,
  99.     &st520bcol
  100. #endif
  101. };
  102.     struct KBDvecs {
  103.         int (*midivec) ();
  104.         int (*vkbderr) ();
  105.         int (*vmiderr) ();
  106.         int (*statvec) ();
  107.         int (*mousevec) ();
  108.         int (*clockvec) ();
  109.         int (*joyvec) ();
  110.         int (*midisys) ();
  111.         int (*ikbdsys) ();
  112.     };
  113.     struct Param {
  114.         char topmode;
  115.         char buttons;
  116.         char xparam;
  117.         char yparam;
  118.         int xmax,ymax;
  119.         int xinitial,yinitial;
  120.     };
  121.     struct KBDvecs *kbdvecs;
  122.     struct Param *paramp;
  123.     char kbdcmds[25];
  124.  
  125. st520move(row, col)
  126. {
  127.         ttputc(ESC);
  128.         ttputc('Y');
  129.         ttputc(row+BIAS);
  130.         ttputc(col+BIAS);
  131. }
  132.  
  133. st520eeol()
  134. {
  135.         ttputc(ESC);
  136.         ttputc('K');
  137. }
  138.  
  139. st520eeop()
  140. {
  141.  
  142. #if    COLOR
  143.         st520fcol(gfcolor);
  144.         st520bcol(gbcolor);
  145. #endif
  146.         ttputc(ESC);
  147.         ttputc('J');
  148. }
  149.  
  150. st520rev(status)    /* set the reverse video state */
  151.  
  152. int status;    /* TRUE = reverse video, FALSE = normal video */
  153.  
  154. {
  155.  
  156.     if(status) {
  157.         ttputc(ESC);
  158.         ttputc('p');
  159.     }
  160.     else {
  161.         ttputc(ESC);
  162.         ttputc('q');
  163.     }
  164. }
  165.  
  166. #if    COLOR
  167. st520fcol(color)
  168. int color;    
  169. {
  170.         if(color == cfcolor || !STncolors)
  171.             return;
  172.         else {
  173.  
  174.             ttputc(ESC);
  175.             ttputc('b');
  176.             ttputc(color & 0x0f);
  177.             cfcolor = color;
  178.         }
  179. }
  180.  
  181. st520bcol(color)
  182. int color;
  183. {
  184.         if(color == cbcolor || !STncolors)
  185.             return;
  186.         else {
  187.             ttputc(ESC);
  188.             ttputc('c');
  189.             ttputc(color & 0x0f);
  190.             cbcolor = color;
  191.         }
  192.  
  193. }
  194. #endif
  195.  
  196. st520beep()
  197. {
  198. #ifdef  BEL
  199.         ttputc(BEL);
  200.         ttflush();
  201. #endif
  202. }
  203.  
  204. st520open()
  205. {
  206.     int i,j,k;
  207.     long phys, log;    /* screen bases */
  208.     
  209. /* IMPORTANT: it is ABSOLUTELY necessary that the default resolution be the
  210.  *    largest possible so that display will allocate (malloc) the maximum
  211.  *    size for the VIDEO arrray
  212.  */
  213.     STrez = Getrez();
  214.     switch(STrez) {
  215.         case 0: /* low res 25x40 16 colors */
  216.             strcpy(sres, "LOW");
  217.             phys = Physbase();
  218.             log  = Logbase();
  219.             Setscreen(log, phys, 1);
  220.             STrez = 1;
  221.             /* fall thru to med res */
  222.  
  223.         case 1: /* med res 25x80 4 colors */
  224.             if (STrez == 1) strcpy(sres, "MEDIUM");
  225.             term.t_nrow = 25 - 1;
  226.             term.t_ncol  = 80;
  227.             grez = 1;
  228. #if    COLOR
  229.             STncolors = 4;
  230.             for(i=0;i<8;i++) {
  231.                 oldpal[i] = Setcolor(i,newpal[i]);
  232.             }
  233. #endif
  234.             break;
  235.         case 2: /* high res 25x80 no colors */
  236.             strcpy(sres, "HIGH");
  237.             term.t_nrow  = 40 - 1;
  238.             term.t_ncol  = 80;
  239.             grez = 2;
  240.             make_8x10(); /* create a smaller font */
  241.             set_40();    /* and go to 40 line mode */
  242. #if    COLOR
  243.             STncolors = 0;
  244. #endif
  245.             break;
  246.     }
  247.  
  248.     revexist = TRUE;
  249.     eolexist = TRUE;
  250.     paramp = (struct Param *)malloc(sizeof(struct Param));
  251.     kbdvecs = (struct KBDvecs *)Kbdvbase();
  252.     paramp -> topmode = 0;
  253.     paramp -> buttons = 4;
  254.     paramp -> xparam = 8;
  255.     paramp -> yparam = 10;
  256.     paramp -> xmax = 79;
  257.     paramp -> ymax = 23;
  258.     paramp -> xinitial = 0;
  259.     paramp -> yinitial = 0;
  260.     Initmous(1,paramp,kbdvecs -> mousevec);
  261.  
  262.     i = 0;
  263.     kbdcmds[i++] = 0x0a;    /*set mouse keycode mode */
  264.     kbdcmds[i++] = 0x08;
  265.     kbdcmds[i++] = 0x0a;
  266.     Ikbdws(i-1,&kbdcmds[0]);
  267.     Cursconf(1,0);
  268.     Cursconf(3,0);
  269.     Cconout(27);Cconout('E');
  270.         ttopen();
  271. }
  272.  
  273. st520close()
  274.  
  275. {
  276.     int i,j,k;
  277.  
  278.     i = 0;
  279.     kbdcmds[i++] = 0x80;    /*reset mouse keycode mode */
  280.     kbdcmds[i++] = 0x01;
  281.     Ikbdws(i-1,&kbdcmds[0]);
  282.     if(grez == 2 && STrez == 2) /* b/w monitor in 40 row mode */
  283.         restore();
  284.  
  285. #if        COLOR
  286.     for(i=0;i<STncolors;i++)
  287.         Setcolor(i,oldpal[i]);
  288. #endif
  289.     Cconout(27);Cconout('E');
  290.     paramp -> buttons = 0;
  291.     Initmous(2,paramp,kbdvecs -> mousevec);
  292.     i = 0;
  293.     kbdcmds[i++] = 0x80;    /*reset the keyboard*/
  294.     kbdcmds[i++] = 0x01;
  295.     Ikbdws(i-1,&kbdcmds[0]);
  296.     Cursconf(1,0);
  297.     ttclose();
  298. }
  299. st520kopen()
  300. {
  301.  
  302. }
  303. st520kclose()
  304. {
  305.  
  306. }
  307.  
  308. st520cres(res)        /* change screen resolution */
  309.  
  310. char *res;        /* resolution to change to */
  311.  
  312. {
  313.     register int nurez;    /* number of res to change to */
  314.     int ierr, i, j ,k;
  315.     long phys, log;    /* screen bases */
  316.     char dum[80]; /* for debugging only */
  317.  
  318.     /* determine the needed resolution */
  319.     if (strcmp(res, "LOW") == 0)
  320.         nurez = 1;
  321.     else if (strcmp(res, "MEDIUM") == 0)
  322.         nurez = 2;
  323.     else if (strcmp(res, "HIGH") == 0)
  324.         nurez = 3;
  325.     else
  326.         return(FALSE);
  327.  
  328.     if(grez == nurez)
  329.         return(TRUE);
  330.         
  331.     if(STrez == 2) { /* b/w monitor-only allow hi | med rez */
  332.         switch(nurez) {
  333.             case 2: /* high res */
  334.                 term.t_nrow  = 40 - 1;
  335.                 term.t_ncol  = 80;
  336.                 make_8x10(); /* create a smaller font */
  337.                 set_40();    /* and go to 40 line mode */
  338.                 grez = 2;
  339.                 sgarbf = TRUE;
  340.                 onlywind(1,1);
  341.                 strcpy(sres, "HIGH");
  342.                 break;
  343.             case 1: /* med res */
  344.                 term.t_nrow  = 25 - 1;
  345.                 term.t_ncol  = 80;
  346.                 restore();
  347.                 grez = 1;
  348.                 sgarbf = TRUE;
  349.                 onlywind(1,1);
  350.                 strcpy(sres, "MEDIUM");
  351.                 break;
  352.             default:
  353.                 mlwrite("Invalid resolution");
  354.                 return(FALSE);
  355.                 break;
  356.         }
  357.     }
  358.     else { /* color monitor-only allow low | medium resolution */
  359.         phys = Physbase();
  360.         log  = Logbase();
  361.         switch(nurez) {
  362.             case 1:
  363.                 term.t_nrow  = 25 - 1;
  364.                 term.t_ncol  = 80;
  365.                 Setscreen(log, phys, 1);
  366.                 STncolors = 4;
  367.                 grez = 1;
  368.                 sgarbf = TRUE;
  369.                 onlywind(1,1);
  370.                 strcpy(sres, "LOW");
  371.                 break;
  372.             case 0:
  373.                 term.t_nrow  = 25 - 1;
  374.                 term.t_ncol  = 40;
  375.                 Setscreen(log, phys, 0);
  376.                 STncolors = 8;
  377.                 grez = 0;
  378.                 sgarbf = TRUE;
  379.                 onlywind(1,1);
  380.                 strcpy(sres, "MEDIUM");
  381.                 break;
  382.             default:
  383.                 mlwrite("%Invalid resolution");
  384.                 return(FALSE);
  385.                 break;
  386.         }
  387.     }
  388.     return(TRUE);
  389. }            
  390.  
  391. STcurblink(onoff)
  392. int onoff;
  393. {
  394.     if(onoff)
  395.         Cursconf(2,0);
  396.     else
  397.         Cursconf(3,0);
  398. }
  399.  
  400.  
  401. char parm_save[28];
  402. long fnt_8x10[640];
  403.  
  404. make_8x10()
  405. {
  406.     int i,j,k;
  407.     long savea23[2];
  408.     
  409.     for(i=0;i<640;i++)
  410.         fnt_8x10[i] = 0;
  411.         
  412.     asm {
  413.     movem.l    A2-A3,savea23(A6)
  414.     
  415.     dc.w    LINEA_INIT        ;A1 -> array of font headers
  416.  
  417.     lea    parm_save(A4),A2    ;A2 -> parameters savearea
  418.     move.l    V_OFF_AD(A0),(A2)+
  419.     move.l    V_FNT_AD(A0),(A2)+
  420.     move.w    V_CEL_HT(A0),(A2)+
  421.     move.w    V_CEL_MY(A0),(A2)+
  422.     move.w    V_CEL_WR(A0),(A2)+
  423.  
  424.  
  425.     move.l    04(A1),A1        ; A1 -> 8x8 font header
  426.     move.l    76(A1),A2        ; A2 -> 8x8 font data
  427.     lea    fnt_8x10+0x100(A4),A3    ; A3 -> 2nd line of font buffer
  428.     move.w    #0x200-1,D0        ; D0 <- longword counter for font xfer
  429.  
  430. fnt_loop:
  431.  
  432.     move.l    (A2)+,(A3)+
  433.     dbf    D0,fnt_loop
  434.         
  435.     movem.l    savea23(A6),A2-A3
  436.     }
  437.     
  438. }
  439.  
  440. set_40()
  441. {
  442.     long    savea23[2];
  443.     
  444.     asm {
  445.     
  446. ;
  447. ;  use the 8x10 character set: 40 line mode
  448. ;
  449.  
  450.     movem.l    A2-A3,savea23(A6)
  451.     
  452.     dc.w    LINEA_INIT
  453.  
  454.     move.l    04(A1),A1        ; A1 -> 8x8 font header
  455.     move.l    72(A1),V_OFF_AD(A0)    ; v_off_ad <- 8x8  offset table addr
  456.     lea    fnt_8x10(A4),A2
  457.     move.l    A2,V_FNT_AD(A0)        ; v_fnt_ad <- 8x10 font data addr
  458.  
  459.     move.w    #10,V_CEL_HT(A0)    ; v_cel_ht <- 10   8x10 cell height
  460.     move.w    #39,V_CEL_MY(A0)    ; v_cel_my <- 39   maximum cell "Y"
  461.     move.w    #800,V_CEL_WR(A0)    ; v_cel_wr <- 800  offset to cell Y+1
  462.  
  463.     movem.l savea23,A2-A3
  464.     }
  465. }
  466.  
  467. set_20()
  468. {
  469.     long    savea23[2];
  470.  
  471.     asm {
  472.         
  473. ;
  474. ;  use the 8x10 character set: 20 line mode
  475. ;
  476.  
  477.     movem.l    A2-A3,savea23(A6)
  478.     
  479.     dc.w    LINEA_INIT        ; A0 -> line A variables
  480.  
  481.     move.l    04(A1),A1        ; A1 -> 8x8 font header
  482.     move.l    72(A1),V_OFF_AD(A0)    ; v_off_ad <- 8x8  offset table addr
  483.     lea    fnt_8x10(A4),A2
  484.     move.l    A2,V_FNT_AD(A0)        ; v_fnt_ad <- 8x10 font data addr
  485.  
  486.     move.w    #10,V_CEL_HT(A0)    ; v_cel_ht <- 10   8x10 cell height
  487.     move.w    #19,V_CEL_MY(A0)    ; v_cel_my <- 19   maximum cell "Y"
  488.     move.w    #1600,V_CEL_WR(A0)    ; v_cel_wr <- 800  offset to cell Y+1
  489.     
  490.     movem.l    savea23,A2-A3
  491.     }
  492. }
  493.  
  494.  
  495. restore()
  496. {
  497.     long savea23[2];
  498.     
  499.     asm {
  500.     
  501. ;  return what was saved in parameter save zone    
  502.  
  503.     movem.l    A2-A3,savea23(A6)
  504.  
  505.     dc.w    LINEA_INIT        ; a0 -> line A variables
  506.  
  507.     lea    parm_save(A4),A2    ; a2 -> parameter save area
  508.     move.l    (A2)+,V_OFF_AD(A0)
  509.     move.l    (A2)+,V_FNT_AD(A0)
  510.     move.w    (A2)+,V_CEL_HT(A0)
  511.     move.w    (A2)+,V_CEL_MY(A0)
  512.     move.w    (A2)+,V_CEL_WR(A0)
  513.     
  514.     movem.l    savea23(A6),A2-A3
  515.     }          
  516. }
  517. GetCurStat(onoff)
  518. int    onoff;
  519. {
  520.     long savea23[2];
  521.  
  522.     asm {
  523.     movem.l    A2-A3,savea23(A6)
  524.  
  525.     dc.w    LINEA_INIT        ; a0 -> line A variables
  526.     move.w    V_DISAB(A0),onoff(A6)    ; 0 = cursor visible
  527.     moveq    #0,D0
  528.     move.w    V_DISAB(A0),D0    
  529.     movem.l    savea23(A6),A2-A3
  530.     }          
  531. }
  532. #else
  533. sthello()
  534. {
  535. }
  536. #endif
  537.  
  538.